package it.gameplanet.client.widgets.articolo;

import static com.google.gwt.user.client.ui.DockPanel.CENTER;
import static com.google.gwt.user.client.ui.DockPanel.SOUTH;
import it.gameplanet.model.Articolo;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.StackPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ViewArticolo extends Composite {

	private final static AcquistaArticoloDialog acquistaDialog = new AcquistaArticoloDialog(new Command() {
		@Override
		public void execute() {
			acquistaDialog.hide();
		}
	});
	
	public ViewArticolo(final Articolo articolo) {
		super();

		StackPanel stackPanel = new StackPanel();
		
		VerticalPanel dialogVPanel = new VerticalPanel();
		dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.add(new HTML("<b>Descrizione:</b>"));
		final HTML descrizione = new HTML(articolo.getDescrizione());
		dialogVPanel.add(descrizione);
		dialogVPanel.add(new HTML("<b>Categoria:</b>"));
		final Label categoria = new Label(articolo.getCategoria());
		dialogVPanel.add(categoria);
		dialogVPanel.add(new HTML("<b>Prezzo:</b>"));
		final Label prezzo = new Label(Double.toString(articolo.getPrezzo()));
		dialogVPanel.add(prezzo);
		dialogVPanel.add(new HTML("<b>Quantit&agrave;:</b>"));
		final Label quantita = new Label(Integer.toString(articolo.getQuantita()));
		dialogVPanel.add(quantita);

		Button acquistaButton = new Button("Acquista");
		
		acquistaButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				acquistaDialog.editNews(articolo);
			}
		});
		
		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
		dialogVPanel.setVerticalAlignment(VerticalPanel.ALIGN_TOP);

		DockPanel containerPanel = new DockPanel();
		containerPanel.addStyleName("gwt-FullWidthAndHeight");
		containerPanel.add(dialogVPanel, CENTER);
		containerPanel.add(acquistaButton, SOUTH);
				
		stackPanel.add(containerPanel, articolo.getNome());
		stackPanel.addStyleName("gwt-FullWidthAndHeight");
		
		initWidget(stackPanel);
	}
}
